using System;
using Nebulosa.Data.Orm;


namespace Nebulosa.Data.Providers {
	public class DbProvider {
		protected static DbProvider instance;
		public static string Trace;
		protected IProvider provider; 
		
		public static DbProvider Instance {
			get {
				if(DbProvider.instance == null) {
					DbProvider.instance = new DbProvider();
				}

				return DbProvider.instance;
			}
		}
		
		public DbProvider() {
			this.provider = new NebulosaProvider();
		}
		
		public DbProvider(string connectionName) {
			this.provider = new NebulosaProvider();
		}
		
		public DbProvider(string connectionString, string provider) {
			this.provider = new NebulosaProvider();
		}
		
		
		
		public void Insert<T>(T model) {
			this.provider.Insert(model);
		}
		
		public void Update<T>(T model) {
			this.provider.Update(model);
		}
		
		public void Delete<T>(T model) {
			this.provider.Delete(model);
		}
		
		public T Get<T>(T model) {
			return this.Cast<T>(this.provider.Get(model));
		}
		
		
		protected T Cast<T>(object o) {
			return (T)o;
		}
	}
}